﻿namespace Leetcode.N0036.V2;
public class Solution
{
    public bool IsValidSudoku(char[][] board)
    {
        var rowFlgs = new bool[9, 9];
        var colFlgs = new bool[9, 9];
        var blockFlgs = new bool[3, 3, 9];

        for (int row = 0; row < 9; row++)
        {
            for (int col = 0; col < 9; col++)
            {
                var val = board[row][col];
                if (val == '.')
                {
                    continue;
                }
                var number = val - '1';
                if (rowFlgs[row, number] || colFlgs[col, number] || blockFlgs[row / 3, col / 3, number])
                {
                    return false;
                }

                rowFlgs[row, number] = true;
                colFlgs[col, number] = true;
                blockFlgs[row / 3, col / 3, number] = true;
            }
        }
        return true;
    }
}